package com.uchengwang.ui.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.uchengwang.R;

/**
 * Created by U城网 on 2018/6/6.
 */

public class ToastManager {

    private static ToastManager manager;
    private ToastManager (){}

    private Toast toast;

    public static ToastManager getManager() {
        if (manager ==null){
            manager = new ToastManager();
        }
        return manager;
    }

    /**
     * 自定义toast
     * */
    public void customToast(Context context, String titleS, String descS){

        LayoutInflater inflater = LayoutInflater.from(context);//调用Activity的getLayoutInflater()
        View view = inflater.inflate(R.layout.layout_custom_toast, null); //加載layout下的布局
        TextView title = view.findViewById(R.id.toast_title);
        title.setText(titleS); //toast的标题
        TextView desc = view.findViewById(R.id.toast_content);
        desc.setText(descS); //toast内容

        if (toast == null && context != null) {
            toast = new Toast(context);
        }
        toast.setGravity(Gravity.CENTER, 0, 0);//setGravity用来设置Toast显示的位置，相当于xml中的android:gravity或android:layout_gravity
        toast.setDuration(Toast.LENGTH_LONG);//setDuration方法：设置持续时间，以毫秒为单位。该方法是设置补间动画时间长度的主要方法
        toast.setView(view); //添加视图文件
        toast.show();



    }
}
